from multiprocessing import Pool
import os,time,random

def worker(msg):
    star_time=time.time()
    print(f'{msg}开始执行，进程号为{os.getpid()}')
    time.sleep(random.random()*2)
    print(msg,f'执行完毕，耗时{time.time()-star_time}s')


if __name__ == '__main__':
    po=Pool(3)#最多床3个进程
    for i in range(0,10):

        po.apply_async(worker,(i,))

    print('---开始执行----')
    po.close()#关闭进程池，关闭后po不在接收数据

    po.join()#等待所有子进程执行完毕，必须放到close语句之后
    print('----结束----')
 